home *** CD-ROM | disk | FTP | other *** search
/ Chip 1996 November / Chip 11-96.iso / workshop / howto / term < prev    next >
Text File  |  1996-05-25  |  40KB  |  960 lines

  1.   The Linux Term HOWTO
  2.   by Bill Reynolds, bill@goshawk.lanl.gov
  3.   May 9, 1994
  4.  
  5.   1.  Introduction
  6.  
  7.  
  8.   1.1.  About This Document
  9.  
  10.  
  11.  
  12.   This  HOWTO  attempts to clear up some of the confusion of using term,
  13.   Michael O'Reilly's remarkable program that  allows  you  to  multiplex
  14.   your  serial  line  and  set  up an ersatz network connection.  By and
  15.   large, the documents that come with term  are  quite  good,  and  this
  16.   HOWTO  is not intended to replace them. The intent of this document is
  17.   to give some background on how term works  and  detail  the  steps  in
  18.   getting  some  of  the  more  common networking services working under
  19.   term. I should emphasize that this document doesn't  cover  everything
  20.   there  is  to  know  about term. After reading it, you should read the
  21.   term manpages, since they include information not contained here.
  22.  
  23.  
  24.   1.2.  What is term?
  25.  
  26.   term is a program, written by Michael O'Reilly (michael@iinet.com.au),
  27.   that  is  run  over  a  serial  line  to allow multiple connections to
  28.   operate concurrently - i.e. you can be downloading a  file  over  your
  29.   modem  while working on a (different) remote system via the same modem
  30.   connection. term can also be used to open up X client windows  over  a
  31.   serial  connection.  Through the tredir utility, term can provide many
  32.   of the ``traditional'' network services: mail, news, ftp, telnet, etc.
  33.   In a sense, term is very much like other serial protocols such as SLIP
  34.   or PPP. term 's advantage is that it can be  run  entirely  from  user
  35.   space,  requiring  neither  kernel  support nor support from system or
  36.   network administrators.
  37.  
  38.  
  39.   2.  How term works
  40.  
  41.   2.1.  Nomenclature
  42.  
  43.  
  44.   I'm assuming you're dialing up a system through some sort of  terminal
  45.   server.  I use the terms ``local'' and ``remote'' to refer to the home
  46.   and network connected systems respectively (unless I use them to  mean
  47.   something else :-).
  48.  
  49.  
  50.   term  provides the local machine, which has no network connection, but
  51.   is connected via a serial line to a remote machine which  is  in  turn
  52.   connected  to  a  network, with network services . Let's look at how a
  53.   machine with  a  ``traditional''  network  connection  provides  these
  54.   services.  First  the user invokes a program, like ftp or telnet, that
  55.   requests a network service. What these program do  is  make  a  system
  56.   call  requesting  network  services. The operating system then obtains
  57.   these services via it's network interface (e.g. it sends and  receives
  58.   packets  over  the  ethernet).  SLIP  and  PPP  do  exactly  this,  by
  59.   converting your modem line into  a  network  interface,  which  is  in
  60.   principle  no different from an ethernet. The downside of this is that
  61.   these protocols make the modem-connected machine part of the  network,
  62.   just  like  any  other  machine.  This  entails all the administrative
  63.   burdens associated with being a network node (more actually, since the
  64.   modem link must also be administered).
  65.  
  66.  
  67.   In the absence of a network connection like SLIP or PPP, what does one
  68.   typically do? Well, you dial up your network connected  machine,  read
  69.   your mail, your news etc, if you need a file, you first transfer it to
  70.   the remote machine and then download it to your  local  machine  using
  71.   kermit  or  its ilk. This is a bit of a pain, especially since you can
  72.   only really do one thing at a time that uses  your  modem  link.   The
  73.   idea  behind term is basically to automate and multiplex this process.
  74.   term is invoked on both the local and remote  machines,  and  the  two
  75.   processes  communicate  with one another over the modem line. When you
  76.   need a network service, you make a request to the local  term  daemon,
  77.   which  forwards the request to the term daemon on the remote, network-
  78.   connected, machine. The result is then returned over the modem line.
  79.  
  80.  
  81.  
  82.   To be more concrete, say you want to retrieve a file  by  ftp.   First
  83.   you  need  a  version  of  ftp that can speak to term. You invoke this
  84.   termftp as you do a regular ftp, say  termftp  nethost.gov,  but  this
  85.   special  version  makes  its  network request to the local term daemon
  86.   instead of the kernel. The local term forwards this request, over  the
  87.   modem  line,  to  the  remote  term,  which opens an ftp connection to
  88.   nethost.gov, and transmits the data back over the modem link. term  is
  89.   smart  enough  to  have many different things going on at once, so you
  90.   can have several different network sessions using the same modem link,
  91.   e.g.  you can be logged into another distant host via termtelnet while
  92.   the termftp transfer is going on.
  93.  
  94.   If this is too abstract (or unclear) don't worry, the important  piece
  95.   of information to get out of this section is that there are two copies
  96.   of term running, one on each end of the modem link.
  97.  
  98.  
  99.   3.  Setting Things Up
  100.  
  101.  
  102.   3.1.  Build term
  103.  
  104.   Hopefully, this should just involve a make, if this doesn't work,  you
  105.   may  have  to  do  some  hacking.  Make  sure that you've got the same
  106.   version on all machines you want to run term on -  different  versions
  107.   of  term  are  incompatible.  Seek out and destroy any old binaries on
  108.   your system - or know how to avoid them.
  109.  
  110.  
  111.   3.2.  Test term
  112.  
  113.  
  114.  
  115.   Do a make test to build term's test daemon. Test works by running  two
  116.   copies of term on your system, a ``local'' and a ``remote'' copy. Both
  117.   of these will read your termrc, so you  can  adjust  their  behaviour.
  118.   Run  test as ./test  so as to avoid your system's test. You should now
  119.   be able to do a trsh and a tupload (try
  120.    tupload ./term /usr/tmp - you should get a copy of the  term   binary
  121.   in  /usr/tmp  ).  The local term's output should show up in local.log,
  122.   the remote's in remote.log.   You can start term up with a -d255  flag
  123.   to  enable  debugging  output  to be written to these files, or enable
  124.   debugging in your termrc.
  125.  
  126.  
  127.   3.3.  Make a Transparent Link
  128.  
  129.  
  130.   Presumably, you can establish a modem connection  between  your  local
  131.   and  remote  hosts. Typically, your dialing into some kind of terminal
  132.   server and connecting to your remote host from  there.  You  are  also
  133.   using  some kind of terminal software, such as kermit or seyon to talk
  134.   to your modem (the examples in this document will  use  kermit,  since
  135.   that  is  what  its  author  uses). If you're having trouble with your
  136.   modem, or your terminal software, take a look  at  the  Serial  HOWTO,
  137.   that should help you out.
  138.  
  139.   Having  established  your  link, you want to make it as transparent as
  140.   possible.  Check the commands on the terminal server (help or  ?  will
  141.   usually  get you started). Go for the 8 bit options whenever possible.
  142.   This may mean changing the way you log in to a  system,  e.g.  if  the
  143.   server  uses rlogin, you may have to use it and give it the -8 flag to
  144.   make it transparent.  Especially watch out for xon/xoff flow  control,
  145.   you  don't  want  that, try to enable rts/cts (hardware) flow control.
  146.   You may need to check your modem docs to learn how to configure it  to
  147.   do 8-bit rts/cts communications.
  148.  
  149.  
  150.   3.4.  Run linecheck
  151.  
  152.  
  153.   linecheck  is  program that is supplied that with term that checks the
  154.   transparency of a link, providing configuration information that  term
  155.   needs  to run correctly.  linecheck will send each of the 255 possible
  156.   eight  bit  characters  over  the  link  and  verify  that  each   was
  157.   transmitted  successfully.  term  needs  to be configured to deal with
  158.   characters that cannot be transmitted over  the  link,  and  linecheck
  159.   determines  what  characters these are. You use linecheck after you've
  160.   established as transparent a modem link as possible. To run linecheck,
  161.   do the following
  162.  
  163.   1. On the remote system, run linecheck linecheck.log.
  164.  
  165.   2. Suspend  your  comm  program  (^Z  under kermit) (otherwise it will
  166.      steal characters from linecheck).
  167.  
  168.   3. On the local system run  linecheck  linecheck.log  >  /dev/modem  <
  169.      /dev/modem.
  170.  
  171.   When  linecheck is done, you'll find a set of numbers at the bottom of
  172.   the linecheck.log files. These should be escaped in the termrc at  the
  173.   other   end  of  the  link.  For  example,  on  my  system,  my  local
  174.   linecheck.log said nothing and my remote linecheck.log said to  escape
  175.   29  and  157.  Therefore, my local termrc escapes these characters and
  176.   my remote termrc escapes nothing. If I escape a character on one  end,
  177.   I  have to also ignore it on the other, so, in this example, I'll have
  178.   to ignore 29 and 157 on my remote system.
  179.  
  180.   If linecheck hangs, try using
  181.  
  182.  
  183.   linecheck linecheck.log 17 19 > /dev/modem < /dev/modem
  184.  
  185.  
  186.  
  187.   this will escape your xon/xoff (flow control) characters,  which  will
  188.   hang your line if you've got software flow control. If this solves the
  189.   hanging  problems,  you'll  want  to  escape  /ignore  17/19  in  both
  190.   termrc's.  If  your  terminal server has other demonic characters that
  191.   will shut  it  down,  try  running  linecheck  with  those  characters
  192.   escaped,  as  above. You can spot these characters if linecheck hangs.
  193.   If this is the case, kill it, then look  in  the  logfiles.  The  last
  194.   characters  transmitted  are  likely  to be the culprits. Try it again
  195.   with these characters escaped.
  196.  
  197.   In summary, my local termrc has the lines
  198.  
  199.   escape 29
  200.   escape 157
  201.  
  202.  
  203.   and my remote termrc has the lines
  204.  
  205.  
  206.   ignore 29
  207.   ignore 157
  208.  
  209.  
  210.   since my remote linecheck.log said to escape 29 and 157.
  211.  
  212.  
  213.   3.5.  Try Running term
  214.  
  215.  
  216.   Log into the remote system, making the link as transparent as possible
  217.   (if  you haven't already).  Fire up term on the remote end.  I use the
  218.   following:
  219.  
  220.   exec term -l $HOME/tlog -s 38400 -c off -w 10 -t 150.
  221.  
  222.   Let's run down each option one by one  (note  that  I  could  just  as
  223.   easily  have put these options in my termrc. I did it this way because
  224.   it saves editing a file while getting term set up).
  225.  
  226.   exec means to destroy your current shell, running the given program in
  227.   its place.  I exec things because I don't intend to use my login shell
  228.   again, so it's just wasting memory. If you're debugging the  link  and
  229.   can reliably kill the remote term, you might not want to do an exec.
  230.  
  231.   -l $HOME/tlog. This logs errors to the file tlog in my home directory.
  232.   Very useful for debugging. No reason not to do this.
  233.  
  234.   -s 38400 : I've got a 14400 baud modem, with compression.  For optimal
  235.   compression  ratios,  I  want to be able to push bits down the pipe as
  236.   fast as possible. For a slower modem, you should use something  lower.
  237.   Note  that if you have a slower machine with 16450 uart on your serial
  238.   port, high baudrates can cause data loss by overloading  the  chip  on
  239.   your serial port. term will recover from this, but if you see a lot of
  240.   error messages in your log file, (or get overrun warnings  from  linux
  241.   kernel  versions  0.99pl15  and up) you again might want to lower this
  242.   number.
  243.  
  244.   -c off : This turns data  compression  off.  I've  got  a  compressing
  245.   modem, and I don't want to compress things twice.
  246.  
  247.   -w  10  -t  150  :  Again, these are options to optimize my fast modem
  248.   link.  I have set my window to 10 and my timeout to 150. This  is  per
  249.   the recommendation in the term_setup man page.
  250.  
  251.   Suspend your comm program (^Z under kermit). You don't want it running
  252.   while term is running, because it will fight with term over the serial
  253.   port. If you can convince your modem to not hang up when you exit your
  254.   comm program (when it toggles DTR), you could just exit the program at
  255.   this point.
  256.  
  257.   Now run term locally. I use:
  258.  
  259.   term  -r  -c off -l $HOME/tlog -s 38400 -w 10 -t 150 \  < /dev/modem >
  260.   /dev/modem &
  261.  
  262.  
  263.   The only option here that is different from the other end  is  the  -r
  264.   option.  You  need  this  on  one  end,  otherwise  term  clients will
  265.   spontaneously die on you. I need to tell term where the modem is, so I
  266.   point  both standard input and output at /dev/modem (that's what the <
  267.   and > do). I also run it in the background, so I can use  this  screen
  268.   for something else if I want to.
  269.  
  270.   term  should  work  now  :-). Try a trsh, and see what happens. If you
  271.   hang, or your link seems slow, take a look at your tlog on  each  end.
  272.   Are  you  getting  timeouts  or  error  messages?  If  so, then you've
  273.   configured something incorrectly. Try  again  (after  you've  finished
  274.   reading  this :-). Note that the connection won't seem blazingly fast,
  275.   especially if you're using compression - it will be  a  little  jumpy.
  276.   The real speed comes in during file transfer and the like.
  277.  
  278.  
  279.  
  280.   3.6.  Gotchas to Watch Out For
  281.  
  282.  
  283.   Are  you  running the right binary? term has been updated quite a lot,
  284.   and many systems have different  versions  of  the  programs  floating
  285.   around.  Make  sure  you're  using  the  right version. Note that this
  286.   applies to linecheck too. You can use bash's type -a  or  the  whereis
  287.   command  to find which program is being run.  term versions after 1.11
  288.   should print out their version number when they start  up.   (Although
  289.   version 1.14 claims to be 1.12.  Sigh.)
  290.  
  291.   Do  you  have the right termrc? Is it called $HOME/.term/termrc?  Some
  292.   systems have pre-installed termrc's, make sure they're gone before you
  293.   set  things  up. If you're running things as root, lookout for /.term.
  294.   term creates files (sockets actually) while it's running,  so  it  has
  295.   its  own  directory,  $HOME/.term,  where  the file termrc goes (note,
  296.   there is no leading dot in termrc!).
  297.  
  298.   Once you've got term running, you might want  to  try  to  get  things
  299.   optimized. A good way to measure the speed of your link is to run tmon
  300.   in one window while up/downloading a file in another. Try  both  (big)
  301.   text  files and compressed files, the plain text should go a factor of
  302.   two-ish faster than the compressed files.  The parameters you want  to
  303.   fiddle with are compression (-c), windows (-w) and timeout (-t).
  304.  
  305.  
  306.   Compression  you  want  this on if you don't have a compressing modem.
  307.   If you do have such a modem, turn compression off, otherwise you'll be
  308.   compressing  things twice, which typically increasesthe amount of data
  309.   transmitted. Compressing modems are ones that use the MNP-5 or V42.bis
  310.   protocols.  Check  your  modem documentation and the message when your
  311.   modem connects.
  312.  
  313.   Windows this is the number of chunks of data, or  packets,  that  term
  314.   will  let  go  over the line before it gets an acknowledgment (or ack)
  315.   from the remote term. For fast modems, increasing this can be  a  win,
  316.   for slower links this can overwhelm the remote end.
  317.  
  318.   Timeout  the  time  term  will  wait  for  an ack. If you've increased
  319.   windows, and you're getting timeouts in your logfile,  try  increasing
  320.   this.
  321.  
  322.   For  14400/V42.bis,  I use -c off -w 10 -t 150. I typically get around
  323.   1700 cps on compressed  files  and  3500  cps  on  ascii  files  using
  324.   tupload.
  325.  
  326.  
  327.   4.  term clients
  328.  
  329.  
  330.  
  331.   term  provides  several  default  clients.  They  include  trsh, tmon,
  332.   tupload, tredir and txconn. This section  will  deal  with  the  first
  333.   three.   The  others each have their own section.  No term client will
  334.   work until you have established a term link.
  335.  
  336.   tmon is a simple utility to monitor the statistics of your  link.   It
  337.   prints  a time histogram of characters transmitted and received. It is
  338.   invoked simply as tmon. Since around version 1.11, tmon has had a  bug
  339.   that causes some information to be garbled. Send me mail if you'd like
  340.   a patch to fix this.
  341.  
  342.   trsh is similar to rsh. Without arguments, it  spawns  an  interactive
  343.   shell  on the remote system (i.e. it logs you in).  trsh is one of the
  344.   primary means of accessing the remote end of the  link  via  term.  If
  345.   given  an  argument,  trsh  executes that argument as a command on the
  346.   remote system. For example trsh ls would give you  a  listing  of  the
  347.   files in your home directory on the remote system.
  348.  
  349.   tupload is the term 's basic file transfer program. It will transfer a
  350.   file, given as it's first argument, to the opposite end of  the  link.
  351.   By  default,  the  files  will  be  put in the same directory that you
  352.   invoked term  from  on  the  other  side.  To  put  files  in  another
  353.   directory,  give  it's  name  as  a  second  argument  to tupload. For
  354.   example, if I want to  put  a  copy  of  the  file  term114.tar.gz  in
  355.   /usr/tmp  on  the  remote  system, I would type tupload term114.tar.gz
  356.   /usr/tmp. There is no client to do a download  -  to  download  files,
  357.   trsh to the remote system and do a tupload.
  358.  
  359.  
  360.   4.1.  Other term Clients
  361.  
  362.  
  363.  
  364.   There  are  now  a  number of programs that have been modified to work
  365.   with term, they include telnet, ftp. Mosaic and many others. They  can
  366.   be found on sunsite.unc.edu in /pub/Linux/apps/comm/termstuff.
  367.  
  368.  
  369.   5.  X and term
  370.  
  371.  
  372.   term  allows  users  to  open  up  X windows on the local machine from
  373.   clients that are running on a machine on the network. This is done  by
  374.   using  the  txconn  client. txconn is executed on the remote, network-
  375.   connected machine, it is invoked simply as txconn. It  goes  into  the
  376.   background and returns a number on the standard output, this number is
  377.   the display number that clients should use to access the X  server  on
  378.   the local machine. An example should make this clear.  I am logged in,
  379.   via trsh, to my remote  term  host,  named  foo.  On  foo,  I  do  the
  380.   following
  381.  
  382.  
  383.  
  384.   foo$ txconn
  385.   Xconn bound to screen 10
  386.   :10
  387.   foo$
  388.  
  389.  
  390.  
  391.   Now, on any host that I wish to run an X client, that is to display on
  392.   my local machine's X server, I do setenv DISPLAY foo:10.  Now  when  I
  393.   start  the client, it will try to connect to screen 10 on machine foo,
  394.   but txconn is listening  to  this  screen,  and  will  forward  all  X
  395.   protocol packets via term to the X server on the local host - i.e. the
  396.   window will open up on your local machine.
  397.   It is possible to go the other way  -  run  a  client  on  your  local
  398.   machine  and  have  it  open  up  a  window on a remote machine on the
  399.   network, however we will defer explaining this  until  after  we  have
  400.   discussed tredir.
  401.  
  402.   txconn is not terribly secure, anyone can connect to your local server
  403.   via term and perform all sorts of mischief. If  you're  worried  about
  404.   this sort of thing, it might be a good idea to consider using xauth to
  405.   authorize your connections. Consult the xauth man page.
  406.  
  407.   The X protocol is not very efficient, it wastes some  bandwidth.  This
  408.   is  usually  not  a problem over an ethernet, but can be murder over a
  409.   modem. X11R6 is supposed to introduce a low bandwidth version of the X
  410.   protocol, LBX. However, this is not of much use, since R6 has not been
  411.   released at the time of this writing. There is a  utility  named  sxpc
  412.   which compresses the X protocol, improving response over serial lines.
  413.   sxpc includes a writeup on how to get it working  with  term,  and  is
  414.   recommended.  You  can  get  sxpc from ftp.x.org in /contrib. The sxpc
  415.   package also explains how to use xauth, so it is doubly recommended.
  416.  
  417.  
  418.   6.  tredir
  419.  
  420.  
  421.   tredir is  one  of  term's  most  powerful  utilities,  allowing  most
  422.   important network services to be performed over a term link. Before we
  423.   explain how to use tredir, it is necessary to give some background  on
  424.   network  services.  We've talked about network services before, but we
  425.   haven't said exactly what they are. Services are just that -  services
  426.   that are provided by the network. Examples of services include telnet,
  427.   which provides logins between machines, the  File  Transfer  Protocol,
  428.   ftp, which transfers files between machines, and smtp, the Simple Mail
  429.   Transfer Protocol, which is used whenever you  send  electronic  mail.
  430.   Each  network  service  has  a  port  number  associated with it.  The
  431.   mapping  of  port  numbers  to  services  is   given   in   the   file
  432.   /etc/services.  This file should be the same on all internet-connected
  433.   machines.
  434.  
  435.   How are these services invoked? Each networked machine runs  a  daemon
  436.   called  inetd,  which  listens  for attempts to connect to the network
  437.   ports. These requests can come from either the network  or  the  local
  438.   machine.  A  network service is obtained by connecting to a particular
  439.   inetd port.  When a network request is made, inetd knows exactly which
  440.   service  is  involved  by the port number that request is made on.  If
  441.   inetd is configured to do so, it then provides the relevant service to
  442.   the  requesting connection. inetd's configuration is given by the file
  443.   /etc/inetd.conf, which has a list of the services that inetd provides.
  444.   For more information, see the man pages for inetd and inetd.conf.
  445.  
  446.   You  can  communicate  directly  with network services by using telnet
  447.   (n.b. not termtelnet). For example, to talk to the sendmail, (or smtp)
  448.   daemon on machine machine_name, you can do a telnet machine_name smtp,
  449.   or telnet machine_name 25, (since 25 is the number assigned to smtp in
  450.   /etc/services).  You  should  get a polite greeting from the daemon on
  451.   the remote machine. This is a very useful trick for debugging  network
  452.   problems and checking ports redirected with tredir (see below).
  453.  
  454.   tredir  works  very  much  like  inetd. It runs in the background as a
  455.   daemon, listening to the network ports, waiting for a request. When  a
  456.   request  for  a service is made, instead of providing that service, as
  457.   inetd does, tredir forwards the request over  the  term  link  to  the
  458.   remote  term,  which makes the request over the network, returning the
  459.   result back over the link to the local client. tredir can forward  the
  460.   request  to any machine on the network, but by default sends it to the
  461.   machine on the other end  of  the  term  link.   tredir  ``redirects''
  462.   network services over the term link (hence the name ``tredir'').
  463.   An  example should make this clear. Let's redirect a local port to the
  464.   telnet port on the remote machine. To do this we would do tredir  2023
  465.   23.   Now,  anyone who connects to port 2023 on the local machine will
  466.   be redirected to port 23 (telnet) on the remote  machine.   Here's  an
  467.   example  session,  the  local  machine is mymachine.modem.home and the
  468.   remote machine is netsun.
  469.  
  470.  
  471.  
  472.   $ tredir 2023 23
  473.   Redirecting 2023 to 23
  474.   $ telnet localhost 2023
  475.   Trying 127.0.0.1...
  476.   Connected to mymachine.modem.home
  477.   Escape character is '^]'.
  478.  
  479.  
  480.   SunOS UNIX (netsun)
  481.   login:
  482.  
  483.  
  484.  
  485.   This example is actually quite useful. If I were  instead  to  do  the
  486.   tredir  on  netsun,  I  could  then  telnet  in  to mymachine from the
  487.   network, simply by connecting to the redirected port on the  networked
  488.   machine (using telnet) - i.e. telnet netsun 2023.
  489.  
  490.   The  general  principle  in  using  tredir  is to redirect the desired
  491.   service to a machine on the network. Our next example will allow us to
  492.   read  news  on the local machine over our term link from a news server
  493.   on the network. News is provided by the nntp service, port number 119.
  494.   All decent newsreaders allow you to specify what port number they will
  495.   use, either via a configuration file or an environment variable. Let's
  496.   specify  this  local  port  to  be  2119. Now, let's say that our news
  497.   server is news.domain.org. We will redirect port 2119 to port  119  on
  498.   news.domain.org,  we will then tell our news reading software that the
  499.   nntp server is located at port 2119 on the local host. Since this will
  500.   depend on the news reader that you use, I will just test the link with
  501.   telnet instead of firing up a newsreader:
  502.  
  503.  
  504.   $ tredir 2119 news.domain.org:119
  505.   Redirecting 2119 to news.domain.org:119
  506.   $ telnet localhost 2119
  507.   Trying 127.0.0.1...
  508.   Connected to mymachine.modem.home.
  509.   Escape character is '^]'.
  510.   200 news.domain.org InterNetNews NNRP server INN 1.4 07-Dec-41 ready
  511.   (posting ok).
  512.  
  513.  
  514.  
  515.   If you can get this far, all you have to do  is  configure  your  news
  516.   reader  to be able to read news via term. (n.b., if you read news like
  517.   this, be sure that in all your posts you set a Reply-To: header to  an
  518.   network email address that you can be reached at, otherwise people who
  519.   want to get in touch with you will be sending mail to whatever (wrong)
  520.   data your newsreader puts in the From: header).
  521.  
  522.  
  523.   6.1.  tredir can bite!
  524.  
  525.  
  526.   The  astute  reader,  after reading the last example will be wondering
  527.   why port 2119 was redirected to port 119 - since  newsreaders  default
  528.   to  port  119,  why couldn't I do a tredir 119 news.domain.org:119 and
  529.   skip the newsreader  configuration?  The  answer  is  that  all  ports
  530.   numbered less than 1024 are ``reserved ports'', and only the superuser
  531.   can listen on them. If one is willing to take a security risk and make
  532.   tredir  an  suid program, or run tredir as root, then one can redirect
  533.   reserve ports and avoid the hassle of renaming services.
  534.  
  535.   Another problem with using reserved  ports  is  that  inetd  is  often
  536.   already  listening  to  these  ports, and only one program at time can
  537.   listen to a port. In order  to  use  such  a  port,  you  must  change
  538.   inetd.conf  so  that  inetd  no longer listens on the port you want to
  539.   redirect. This is most easily done by commenting out the line with the
  540.   offending  service  by  putting  a # character at the beginning of the
  541.   line. The superuser must then send inetd a HUP signal  to  get  it  to
  542.   reread its configuration.
  543.  
  544.   All of the services we've been discussing so far are TCP (Transmission
  545.   Control Protocol) services -  TCP  is  just  a  protocol  for  sending
  546.   packets  (data)  over  a net. term only works with TCP packets.  There
  547.   are other network protocols, such as UDP (the User Datagram  Protocol)
  548.   that  are  used for things like network file systems, that term cannot
  549.   handle. If you need to obtain a UDP service, like  NFS,  over  a  term
  550.   link,  you  are  out  of  luck.  In this case, it would behoove you to
  551.   consider PPP or SLIP.
  552.  
  553.  
  554.  
  555.   6.2.  Stupid tredir tricks
  556.  
  557.  
  558.   In this section we will describe some of  the  more  common  uses  for
  559.   tredir.  We  have  already  described  how to redirect nntp and telnet
  560.   services, here we will give some more complicated examples.
  561.  
  562.  
  563.   6.2.1.  X windows
  564.  
  565.  
  566.   In a previous section, we described how to get an X client running  on
  567.   the  network  to  open a window on your home machine using txconn. The
  568.   same technique could be used on your home machine to display a  client
  569.   on  the machine at the remote end of your term link.  But how does one
  570.   display an X client on a network machine that is not the  remote  end?
  571.   The  answer  lies  in knowing that X uses a particular network service
  572.   just like the other  programs  we've  been  discussing.  An  X  server
  573.   listens  for  network  request  on a port whose number is given by the
  574.   formula  port = 6000 + display  number,  e.g.  an  X  server  managing
  575.   screen  0  on a machine would listen to port 6000, if it were managing
  576.   screen 2, it would listen on port 6002.  When  you  set  your  DISPLAY
  577.   environment variable to xmachine:n, your X clients will try to connect
  578.   to port 6000 +n on xmachine.
  579.  
  580.   We can use this to trick X clients on your local machine  to  open  up
  581.   windows  on  remote  displays.  Let's  say I want to open up an xterm,
  582.   running on my local machine, on display 0 of machine  xmachine,  which
  583.   is  running  someplace  on  the network.  I first pick a local display
  584.   number, say 2 (don't use 0, since that's what your local X server will
  585.   be  using). I will map this display to display 0 on xmachine. In terms
  586.   of ports, this means I want to redirect the local  port  6002  to  the
  587.   remote port 6000.  I do the following
  588.  
  589.  
  590.  
  591.   $ tredir 6002 xmachine:6000
  592.   $ setenv DISPLAY localhost:2
  593.   $ xterm
  594.  
  595.   This should open up an xterm on machine xmachine.  Note that I set the
  596.   DISPLAY to localhost:2. This is because X clients will  sometimes  use
  597.   unix  domain  sockets instead of internet domain sockets, at their own
  598.   option, when connecting to a local display, if DISPLAY is set  to  :2.
  599.   localhost:2  says to use a tcp connection.
  600.  
  601.   Note  that  as  far  as xmachine is concerned, the X request is coming
  602.   from the machine on the remote end of your term link (remotemachine) -
  603.   so  if  you  need to authorize the connection, you should either do an
  604.   xhost  +  remotemachine  on  xmachine  or  use  xauth  to  update  the
  605.   .Xauthority file on your local machine for display number 2, using the
  606.   key from xmachine.
  607.  
  608.   Again, to speed up X connections, you can use the program sxpc,  which
  609.   includes an explanation of how to use tredir to establish the link and
  610.   authorize it using xauth.
  611.  
  612.  
  613.   6.2.2.  Mail with term
  614.  
  615.  
  616.   Well, you asked for it. Electronic mail has the justifiable reputation
  617.   of  being  one  of the most difficult things to get working right on a
  618.   UNIX system. To really get term working correctly with mail means that
  619.   you  have  to  understand how mail works, which is beyond the scope of
  620.   this document. To learn more about mail, you should consult a book  on
  621.   UNIX  system  administration  and/or the comp.mail.misc FAQ, available
  622.   for anonymous ftp on rtfm.mit.edu in pub/usenet/comp.mail.misc.  There
  623.   are  also  currently  two  packages  available  for  anonymous  ftp on
  624.   sunsite.unc.edu that will help you get mail running under term -  they
  625.   are  term.mailerd+smail  by Byron A. Jeff and the BCRMailHandlerXXX by
  626.   Bill C. Riemers.
  627.  
  628.   That being said, we'll give a thumbnail description of how mail works.
  629.   There  are  two  parts  to  getting mail running, sending messages and
  630.   receiving messages. We'll begin with sending messages from your  local
  631.   box to the network.
  632.  
  633.   There  are  two  classes  of mail programs. The first is the mail user
  634.   agent (MUA). MUA's help you read, compose and send messages.  Examples
  635.   of  MUA's  are  elm,  pine,  Mail  and  vm.  MUA's don't really do any
  636.   networking, they just put the messages together -  the  real  work  of
  637.   sending  mail  is  done by the second class of mail programs, the mail
  638.   transfer agents (MTA's). These are invoked by the MUA's. They take the
  639.   message,  decide  where to send it by looking at the address, and then
  640.   actually deliver it over the network.
  641.  
  642.   The two most common MTA's on Linux systems are sendmail and smail. The
  643.   basic  idea  is to get your MTA to connect to another MTA running on a
  644.   machine on the net that will know what to do with your  message.  This
  645.   is  done  by  redirecting  a  local  port  to the smtp port on the net
  646.   machine. You then have to tell you MTA to take any message it  doesn't
  647.   know  what to do with and send it out over the redirected port on your
  648.   local machine to the MTA on the remote machine, which will then  route
  649.   your message to its correct destination.
  650.  
  651.   How  do  we do this using smail?  We first redirect a port to the smtp
  652.   port on the network mail machine (mailhost):
  653.  
  654.   tredir XXXX mailhost:25
  655.  
  656.   here XXXX is the port number that the  smail  on  the  localhost  will
  657.   connect  to  (note  that  I  have  to  give  this  port  a  name in my
  658.   /etc/services to get  smail  to  recognize  it).   smail  has  several
  659.   configuration  files  that  usually live in /usr/local/lib/smail.  The
  660.   ones we care about are config, routers and transports. Note  that  I'm
  661.   assuming  you've already got smail configured correctly for local mail
  662.   -  delivery  to  files  and  pipes  and  such.   Again,  consult   the
  663.   documentation if you don't.
  664.  
  665.   In the file config, we put the following definition:
  666.  
  667.  
  668.   smart_path=localhost
  669.  
  670.  
  671.  
  672.   localhost  is  the machine that that smail connects to when it doesn't
  673.   know what to do with a message.
  674.  
  675.   In routers we put
  676.  
  677.  
  678.  
  679.   smart_host:
  680.   driver=smarthost,
  681.   transport=termsmtp;
  682.   path = localhost
  683.  
  684.  
  685.  
  686.   In transports we put
  687.  
  688.  
  689.  
  690.   termsmtp:        driver=tcpsmtp,
  691.           inet,
  692.           return_path,
  693.           remove_header="From",
  694.           append_header="From: YOUR_NET_ADDRESS",
  695.           -received,
  696.           -max_addrs, -max_chars;
  697.           service=YOUR_SMTP_SERVICE,
  698.  
  699.  
  700.  
  701.   In the above, the header lines change the  From  header  in  all  your
  702.   outgoing  mail  to the address, YOUR_NET_ADDRESS, which is the network
  703.   address you want mail for sent. If more than one user is going  to  be
  704.   using  your  term  link,  you'll have to do something more fancy, like
  705.   keep a database of local user's network addresses and insert these  in
  706.   the From: headers.
  707.  
  708.   The  service  line  is  the  name  of the local portnumber that you've
  709.   redirected to the smtp port on the network connected  machine.  On  my
  710.   version  of smail, I can't just set this to a number, I have to set it
  711.   to a name, like ``foo'', and then define ``foo'' in  my  /etc/services
  712.   to  be the number of my redirected port. If you use an suid tredir and
  713.   just redirect the smtp port (25), you don't need to define this.
  714.  
  715.   This should be enough to get you going. If you decide to use sendmail,
  716.   the  principles  are the same but the details differ.  Ronald Florence
  717.   (ron@mlfarm.com) tells me tells me that the stock Sun  sendmail  won't
  718.   send  multiple  queued  messages  over a redirected port; BSD sendmail
  719.   8.6.9 works fine.  He made the following changes to sendmail.cf to get
  720.   it  working  with term. In his case, the default sendmail port (25) is
  721.   used for SMTP traffic over a  local  ethernet,  so  Internet  mail  is
  722.   forwarded to a redirected TCP port.
  723.  
  724.  
  725.  
  726.  
  727.   #
  728.   #Create the termsmtp mailer, which sends mail via a re-directed TCP port
  729.   #
  730.   Mtermsmtp,P=[TCP], F=mDFMuCXe, S=22, R=22, A=TCP $h PORTNUMBER
  731.  
  732.  
  733.  
  734.   Here,  PORTNUMBER  is  the  number of the redirected port on the local
  735.   machine. This should be  an  unused  port  over  2000.  We  next  tell
  736.   sendmail  to  which  machine  to  connect  to, and set termsmtp as the
  737.   default mailer.
  738.  
  739.  
  740.   #
  741.   # major relay mailer
  742.   #
  743.   DMtermsmtp
  744.   #
  745.   # major relay host: use the $M mailer to send mail to other domains
  746.   #
  747.   DR HOSTNAME
  748.   CR HOSTNAME
  749.  
  750.  
  751.  
  752.   Here HOSTNAME is the name of your local host (does  localhost  work?).
  753.   The last entry goes under Rule 0 to forward Internet mail.
  754.  
  755.  
  756.   # Pass other valid names up the ladder to our forwarder
  757.   R$*<@$*.$+>$*           $#$M    $@$R $:$1<@$2.$3>$4     user@any.domain
  758.  
  759.  
  760.  
  761.   When  the term connection is established to the Internet host, run the
  762.   following commands on the local machine.
  763.  
  764.  
  765.   tredir PORTNUMBER internet.host:25
  766.   /usr/lib/sendmail -q
  767.  
  768.  
  769.  
  770.   We now turn to receiving electronic mail using term. We'll assume that
  771.   mail  is  sent  to  your  account on the network machine mailhost. The
  772.   simplest solution is to just use trsh  or  termtelnet  to  log  on  to
  773.   mailhost and read your mail on there.  However, it is also possible to
  774.   have your mail automatically downloaded to your local machine. One way
  775.   to  do  this  is  to  use  the  Post  Office Protocol, (POP).  POP was
  776.   designed for exactly this purpose: to deliver mail  to  machines  that
  777.   have intermittent network connections. To use POP, you must have a POP
  778.   server installed on mailhost. Assuming that you do, you can then use a
  779.   POP  client to download your mail every few minutes.  This is done, as
  780.   you might expect, using tredir. The POP  service  is  110  (n.b.  that
  781.   there  is  an  older  protocol,  POP-2,  which  uses port 109, in this
  782.   document we describe POP-3, which is the latest version of POP). There
  783.   are  several  POP  clients  available.  One,  written using the script
  784.   language perl is pop-perl-1.X, written by William Perry and maintained
  785.   by myself - it can be found on sunsite in /pub/Linux/system/Mail.
  786.  
  787.   To  use  POP,  you  redirect  a local port to port 110 on mailhost and
  788.   configure your client to retrieve your mail from localhost  using  the
  789.   local  port.  As  an  example, we'll assume that there is a POP server
  790.   running on mailhost. We'll redirect the local port 2110, and  fire  up
  791.   the pop-perl client:
  792.  
  793.   $ tredir 2110 mailhost:110
  794.   Redirecting 2110 to mailhost:110
  795.   $ pop
  796.   Username: bill
  797.   Password: <enter your password for mailhost>
  798.   Pop Host: localhost
  799.   Pop Port: 2110
  800.   Starting popmail daemon for bill
  801.  
  802.  
  803.  
  804.  
  805.   If  you do not have a POP server available, the BCRMailHandler package
  806.   has a program to download your mail over a term  link  to  your  local
  807.   machine. I have not used it, but anyone who has is welcome to comment.
  808.  
  809.  
  810.  
  811.   7.  Automating Things
  812.  
  813.  
  814.  
  815.   Now that you know how to get all of your network services  over  term,
  816.   it  would  be  nice  to  set  things  up  so  your  link is set up and
  817.   configured automatically. There are basically an  infinite  number  of
  818.   ways of doing this, depending on what comm program you use and how you
  819.   log in to your remote system.
  820.  
  821.   One program, that I haven't used, but I've heard  is  quite  nice,  is
  822.   fet:  a  front  end  for term. It is designed to log you into a remote
  823.   system and fire up term and all your tredir's.  Any  comments  on  fet
  824.   would be most welcome.
  825.  
  826.   I'll  now  give an example of a set of commands that use kermit to log
  827.   into  the  remote  system  and  then  performs   all   of   the   term
  828.   initializations.  Obviously,  if you use these examples, you will have
  829.   to modify them for your own login procedures.
  830.  
  831.   The command which is actually invoked is the shell script knet,  given
  832.   by:
  833.  
  834.  
  835.  
  836.  
  837.   #!/bin/sh
  838.   /usr/bin/kermit -y $HOME/.kerm_term > $HOME/klog < /dev/null 2>& 1
  839.   exec $HOME/bin/tstart >> $HOME/klog 2>& 1
  840.  
  841.  
  842.  
  843.   The script .kerm_term is given by:
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.   pause 2
  860.   # The number you want to dial
  861.   output atdtXXXXXXX \13
  862.   # Login to the terminal server
  863.   input 145 {name: }
  864.   output MYNAME \13
  865.   input 3 {word: }
  866.   output MYPASSWORD \13
  867.   input 5 {xyplex>}
  868.   # Make the line transparent
  869.   output term telnet-t \13
  870.   output term stopb 1 \13
  871.   # Connect to the remote host
  872.   output telnet remotehost.somedomain.org \13
  873.   input 10 {ogin: }
  874.   output MYOTHERNAME \13
  875.   input 3 word:
  876.   output MYOTHERPASSWORD \13
  877.   pause 5
  878.   # Fire up term on the remote host
  879.   output exec term -s 38400 -l $HOME/tlog -w 10 -t 150  \13
  880.   # Suspend kermit
  881.   !killall -STOP kermit
  882.  
  883.  
  884.  
  885.  
  886.   and  finally,  the script tstart which fires up the local term and its
  887.   clients is given by
  888.  
  889.  
  890.  
  891.   #!/bin/sh
  892.   #
  893.   # Fire up term
  894.   #
  895.   /usr/local/bin/term -l $HOME/tlog -s 38400 -r -w 10 -t 150 < /dev/modem > /dev/modem &
  896.   #
  897.   # Let it get going
  898.   #
  899.   sleep 3
  900.   #
  901.   # This lets mail get out, can read news here, can pick up my mail here
  902.   #
  903.   /usr/local/bin/tredir 2025 25 2119 newshost:119 2110 pophost:110
  904.   #
  905.   # So I can open up Xwindows here
  906.   #
  907.   /usr/local/bin/trsh -s txconn
  908.   #
  909.   # So I will receive mail....
  910.   #
  911.   /usr/local/bin/pop
  912.   #
  913.   # Clean out the queue, in case of boo-boos
  914.   #
  915.   /usr/bin/runq
  916.   #
  917.   # Done now
  918.   #
  919.   echo ^G^G > /dev/console
  920.  
  921.  
  922.  
  923.  
  924.  
  925.   As I said, there are zillions of ways to do this, these are just meant
  926.   as examples to get you started.
  927.  
  928.  
  929.   8.  Other Stuff
  930.  
  931.  
  932.   I would like future versions of this HOWTO to include some more stuff,
  933.   however I've run out of gas for the time being (maybe next month). Any
  934.   help  would  be  greatly  appreciated.  Some things that might be nice
  935.   include,
  936.  
  937.  
  938.   o  A complete list of term clients.
  939.  
  940.   o  How to port a client to term
  941.  
  942.   o  Other versions of  term  :  Olaf  Titz's  patches,  the  term+share
  943.      package. Any others?
  944.  
  945.   o  Suggestions.
  946.  
  947.   Anyways,  if  you  have comments, criticisms, suggestions, or anything
  948.   else to say about this document, please fire away. I'm  Bill  Reynolds
  949.   and can (currently) be reached at bill@goshawk.lanl.gov.
  950.  
  951.  
  952.   9.  Acks
  953.  
  954.   Thanks  go  to a lot of people. First and foremost to Michael O'Reilly
  955.   and all the developers of term, who have provided us with such a great
  956.   tool.  I  would  also  like  to  thanks everyone who gave feedback and
  957.   contributed to this HOWTO, they include Ronald Florence, Tom  Payerle,
  958.   Bill  C.  Riemers,  Hugh Secker-Walker, Matt Welsh and everybody whose
  959.   mail I've accidently deleted or forgotten to mention.
  960.